package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Stock;
import com.egao.orderB.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 库存
 * @author : Doman
 * @date : 2021-12-23 16:30:08
 * @version ：1.0
 */

@Api(tags = "库存")
@RestController
@RequestMapping("/api/orderB/stock")
public class StockController extends BaseController {

	@Autowired
	private StockService stockService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:stock:list')")
  @ApiOperation(value ="分页查询库存",notes = "" +
    "limit:每页显示几行 必填\n" +
    "page:第几页 必填\n" +
    " \n\n\n" +
    "返回的结果:\n" +
    "id:id\n" +
    "customerId:客户id\n" +
    "customer:客户\n" +
    "sku:SKU\n" +
    "name:货名\n" +
    "num:件数\n" +
    "pack:包装\n" +
    "weight:重量\n" +
    "length:长\n" +
    "width:宽\n" +
    "high:高\n" +
    "volume:体积\n" +
    "totalVolume:总体积\n" +
    "palletNum:托盘数\n" +
    "orderNum:排序\n" +
    "createTime:创建时间\n" +
    "createUser:创建人\n" +
    "updateTime:更新时间\n" +
    "updateUser:更新人\n" +
    "",httpMethod = "POST")
  @ApiPageParam
  @PostMapping("/list")
  public JsonResult page(PageResult2<T> page, Stock stock) throws Exception{
    return stockService.list(page, stock, getLoginUser());
  }

  /**
   * 查询全部库存
   */
  @PreAuthorize("hasAuthority('orderB:stock:list')")
  @ApiOperation("查询全部库存")
  @PostMapping("/listAll")
  public JsonResult list(Stock stock){
    return stockService.list(stock, getLoginUser());
  }

  /**
   * 根据id查询库存
   */
  @PreAuthorize("hasAuthority('orderB:stock:list')")
  @ApiOperation("根据id查询库存")
  @PostMapping("/get")
  public JsonResult get(Stock stock) {
    return stockService.getById(stock);
  }


  /**
   * 添加库存
   */
  @PreAuthorize("hasAuthority('orderB:stock:save')")
  @OperLog(value = "库存", desc = "添加", param = false, result = true)
  @ApiOperation(value ="添加库存",notes = "" +
    "customerId:客户id\n" +
    "customer:客户\n" +
    "sku:SKU\n" +
    "name:货名\n" +
    "num:件数\n" +
    "pack:包装\n" +
    "weight:重量\n" +
    "length:长\n" +
    "width:宽\n" +
    "high:高\n" +
    "volume:体积\n" +
    "totalVolume:总体积\n" +
    "palletNum:托盘数\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/save")
  public JsonResult save(Model model, Stock stock) {
    return stockService.save(stock, getLoginUser());
  }

  /**
   * 修改库存
   */
  @PreAuthorize("hasAuthority('orderB:stock:update')")
  @OperLog(value = "库存", desc = "修改", param = false, result = true)
  @ApiOperation(value ="修改库存",notes = "" +
    "id:id\n" +
    "customerId:客户id\n" +
    "customer:客户\n" +
    "sku:SKU\n" +
    "name:货名\n" +
    "num:件数\n" +
    "pack:包装\n" +
    "weight:重量\n" +
    "length:长\n" +
    "width:宽\n" +
    "high:高\n" +
    "volume:体积\n" +
    "totalVolume:总体积\n" +
    "palletNum:托盘数\n" +
    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/update")
  public JsonResult update(Model model, Stock stock) {
    return stockService.update(stock, getLoginUser());
  }

  /**
   * 删除库存
   */
  @PreAuthorize("hasAuthority('orderB:stock:remove')")
  @OperLog(value = "库存", desc = "删除", result = true)
  @ApiOperation(value ="删除库存",notes = "" +
    "id:id\n" +
    "",httpMethod = "POST")
  @PostMapping("/remove")
  public JsonResult remove(Stock stock ) {
    return stockService.remove(stock, getLoginUser());
  }

}
